package com.plant.order.controller;

import com.plant.common.result.Result;
import com.plant.order.domain.GoodsOrder;
import com.plant.order.domain.Order;
import com.plant.order.service.OrderService;
import com.plant.order.vo.GoodsVo;
import com.plant.order.vo.OrderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderService ordersService;

    @GetMapping("/findOrder")
    public Result findOrder(@RequestParam("orderId") String orderId){
       List<Order> orderList = ordersService.findOrder(orderId);
        return Result.ok(orderList);
    }

    @GetMapping("findAll")
    public Result findAll(){
        List<GoodsVo> orderList = ordersService.findAll();
        return Result.ok(orderList);
    }

    @GetMapping("findAllStatus")
    public Result findAllStatus(){
        List<GoodsVo> orderList = ordersService.findAllStatus();
        return Result.ok(orderList);
    }

    @GetMapping("findAllOrder/{userId}")
    public Result findAllOrder(@PathVariable Integer userId){
        List<GoodsVo> orderList = ordersService.findAllOrder(userId);
        return Result.ok(orderList);
    }

    @GetMapping("findById/{id}")
    public Result findById(@PathVariable Integer id){
        GoodsVo order = ordersService.findById(id);
        return Result.ok(order);
    }

    @PostMapping("updateOrder")
    public Result updateOrder(@RequestBody GoodsOrder goodsOrder){
      int i= ordersService.updateOrder(goodsOrder);
      if(i>0){
          return Result.ok(i);
      }else{
          return Result.fail("修改失败");
      }
    }
    @GetMapping("findByOrderStatus/{orderStatus}/{userId}")
    public Result findByOrderStatus(@PathVariable("orderStatus") Integer orderStatus,@PathVariable("userId") Integer userId){
        List<GoodsVo> orderList = ordersService.findByOrderStatus(orderStatus,userId);
        return Result.ok(orderList);
    }

    //我的花店查询的租赁订单
    @GetMapping("findAllOrderTime/{userId}")
    public Result findAllOrderTime(@PathVariable Integer userId){
        List<OrderEntity> orderList = ordersService.findAllOrderTime(userId);
        return Result.ok(orderList);
    }


}
